package com.ct.deadlockdetetor.controller;

import com.ct.deadlockdetetor.common.controller.BaseController;
import com.ct.deadlockdetetor.common.pojo.CommonResult;
import com.ct.deadlockdetetor.common.pojo.TableDataInfo;
import com.ct.deadlockdetetor.domain.allocation.dto.AllocationQueryDTO;
import com.ct.deadlockdetetor.domain.allocation.dto.RequestResourceDTO;
import com.ct.deadlockdetetor.service.ResourceAllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/allocation")
public class ResourceAllocationController extends BaseController {

    @Autowired
    private ResourceAllocationService resourceAllocationService;

    /**
     * 向资源请求实例
     */
    @PostMapping("/request")
    public CommonResult<Void> requestResource(@Validated @RequestBody RequestResourceDTO requestResourceDTO) {
        return toCommonResult(resourceAllocationService.requestResource(requestResourceDTO));
    }

    /**
     * 查看分配资源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AllocationQueryDTO allocationQueryDTO) {
        return getTableDataInfo(resourceAllocationService.list(allocationQueryDTO));
    }
}